package com.xh.lesson.controller;


import com.xh.lesson.aop.annotation.LogAnnotation;
import com.xh.lesson.entity.SysHouseFun;
import com.xh.lesson.service.SysHouseFunService;
import com.xh.lesson.utils.DataResult;
import com.xh.lesson.vo.req.AllUpdateReqVo;
import com.xh.lesson.vo.req.HomeAddReqVO;
import com.xh.lesson.vo.req.HomeUpdateReqVo;
import com.xh.lesson.vo.resp.HomeInfo;
import com.xh.lesson.vo.resp.PageVO;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 柴&许
 * @since 2021-07-01
 */
@RestController
@RequestMapping("/sys")
public class SysHouseFunController {
    @Autowired
    private SysHouseFunService sysHouseFunService;


    @GetMapping("/indoor/{id}")
    @ApiOperation(value = "查找组织接口")
    @LogAnnotation(title = "屋内管理",action = "查找组织")
    @RequiresPermissions("sys:indoor:list")
    public DataResult<AllUpdateReqVo> deleted(@PathVariable("id") Integer id){
        DataResult result = DataResult.success();
        List<AllUpdateReqVo> list = sysHouseFunService.selectHomeById(id);
        result.setData(list);
        return result;
    }

    @PostMapping("/indoors")
    @ApiOperation(value = "查找组织接口")
    @LogAnnotation(title = "屋内管理",action = "查找组织")
    @RequiresPermissions("sys:indoor:list")
    public DataResult<PageVO<HomeInfo>> selectAll(@RequestBody HomeInfo vo){
        DataResult result = DataResult.success();
        PageVO<HomeInfo> pageVO = sysHouseFunService.selectAll(vo);
        result.setData(pageVO);
        return result;
    }


    @PutMapping("/indoor")
    @ApiOperation(value = "更新组织信息接口")
    @LogAnnotation(title = "屋内管理",action = "更新组织信息")
    @RequiresPermissions("sys:indoor:update")
    public DataResult<HomeUpdateReqVo> updateHome(@RequestBody @Valid HomeUpdateReqVo vo){
        sysHouseFunService.UpdateHome(vo);
        return DataResult.success();
    }


    @PostMapping("/indoor")
    @ApiOperation(value = "添加组织信息接口")
    @LogAnnotation(title = "屋内管理",action = "添加组织信息")
    @RequiresPermissions("sys:indoor:add")
    public DataResult<SysHouseFun> addIndoor(@RequestBody @Valid HomeAddReqVO vo ){
        sysHouseFunService.addHome(vo);
        return DataResult.success();
    }

    @DeleteMapping("/indoor/{id}")
    @ApiOperation(value = "删除组织信息接口")
    @LogAnnotation(title = "屋内管理",action = "删除组织信息")
    @RequiresPermissions("sys:indoor:deleted")
    public DataResult<SysHouseFun> deletedIndoor(@PathVariable("id")Integer id){
        sysHouseFunService.deleteHouseFun(id);
        return DataResult.success();
    }


    @DeleteMapping("/indoors")
    @ApiOperation(value = "删除组织信息接口")
    @LogAnnotation(title = "屋内管理",action = "删除组织信息")
    @RequiresPermissions("sys:indoor:deleted")
    public DataResult<SysHouseFun> deletesIndoors(@RequestBody List<Integer> homeIds){
        sysHouseFunService.deleteHouseFun(homeIds);
        return DataResult.success();
    }


}

